<?php
/**
 * Класс для отображения новостей.
 * 
 * Вывод новостей, отображение форм создания и изменения новстей, удаление.
 * 
 * @author Русин Иван <ivanrsn@gmail.com>
 * @version 1.0
 */
class View_News{

  /**
   * функция выводит 5 новостей соответственно шаблону главной страницы.
   *
   * @return void
   */
   public static function showFiveNewsOnGeneral(){
	$objDB = Service_Database::instance();
	$arrNews = $objDB->select("select id,title,description,type from neftemagnat_news ORDER BY id desc LIMIT 5");
        ?>
        <div class="general_br">
            <ul class="one_column_gn">
                <?
                $last = count($arrNews)-1;
                foreach ($arrNews as $key => &$arrOneNews){
                ?>
                <li <?if($key == $last){?>class="last_child"<?}?>>
                       <a href="<?=W_ABSPATH?>news/<?=$arrOneNews['type']?>/<?=$arrOneNews['id']?>" class="head_news" 
                       title="Подробности"><?=$arrOneNews['title']?></a>
                        <p><?=$arrOneNews['description']?></p>
                </li>
                <?}?>
            </ul>
        </div>
        <?
    }
    
  /**
   * функция выводит горячую новость с изображением на главную страницу.
   *
   * @return void
   */
   public static function showHotNewsOnGeneral(){
	$objDB = Service_Database::instance();
	$arrOneNews = $objDB->selectOne('select id,title,description,type from '.DB_PREFIX.'news WHERE hot=1 ORDER BY id desc LIMIT 1');
        ?>

        <div class="important_news">
        <div class="important_block">
            <?  if (file_exists(IMAGES.'news/news_'.$arrOneNews['id'].'.jpg')) {?>
                <img title="" alt="" class="left" src="<?=W_IMAGES.'news/news_'.$arrOneNews['id'].'.jpg'?>">
                <?}?>
                <a class="head_imp" href="<?=W_ABSPATH?>news/<?=$arrOneNews['type']?>/<?=$arrOneNews['id']?>"><?=$arrOneNews['title']?></a>
                <p><?=$arrOneNews['description']?></p>
                <a class="clear right" href="<?=W_ABSPATH?>news/<?=$arrOneNews['type']?>/<?=$arrOneNews['id']?>">Читать дальше</a>
                <div class="clear"></div><!-- .clear -->
        </div><!-- .important_block -->
        </div><!-- .important_news -->

        <?
    }
    
    public static function viewBlockNews($arrNews){
        $last = count($arrNews)-1;
        foreach($arrNews as $key => &$arrOneNews)
        {
            $arrDate = explode('-',$arrOneNews['date']);
            $strMonth = Service_Date::getMonthNameR((int) $arrDate[1], true);
            $strDate = preg_replace("/^(\d{4})-(\d{2})-(\d{2})$/","$3 $strMonth, $1",$arrOneNews['date']);
            ?>
            <li <?if($key == $last){?>class="last_child"<?}?>>
                <span class="date"><b><?=$strDate?></b><ins>//</ins></span>
                <span class="rubric_part"><?=$arrOneNews['lable']?></span>
                <p>
                <a href="<?=W_ABSPATH?>news/<?=$arrOneNews['type']?>/<?=$arrOneNews['id']?>"><?=$arrOneNews['title']?></a>
                </p>
            </li>            
        <?
        }
    }
}
?>